<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<script type="text/javascript">
	function showForm(id,name,roleId,companyId,status){		
		$('.accountId').val(id);
		$('.accountName').val(name);
		$('select[name=roleId]').val(roleId);
		$('.status').removeAttr('checked');
		if(status == '1'){
			$('.status').attr('checked','true');
		}
		$.post('${pageContext.request.contextPath}/auth/login-emp-approve',{companyId : companyId}, function( data ) {
			$( ".employee-ajax" ).html( data );
		});
	}
	
</script>
<div class="form-search">
	<h3>Thông tin kích hoạt</h3>
	<form action="${pageContext.request.contextPath}/auth/object-status" id="my-form">
		<input name="accountId" class="accountId" type="hidden">
		<table>
			<tr>
				<td class="column1">Email:</td><td><input name="accountName" class="accountName" type="text" value="${accountName}"></td>
			</tr>
			<tr>
				<td class="column1">Quyền:</td>
				<td>
					<select name="roleId">
						<c:forEach items="${rolies}" var="obj">
							<c:choose>
								<c:when test="${obj.roleId == roleId}"> 
									<option value="${obj.roleId}" selected="selected">${obj.roleDescription}</option>
								</c:when>
								<c:otherwise><option value="${obj.roleId}">${obj.roleDescription}</option></c:otherwise>
							</c:choose>				
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td class="column1">Trạng thái:</td>
				<td>
					<c:choose>
						<c:when test="${status == 1}"> 
							<input name="status" class="status" type="checkbox" value="1" checked="checked"/>
						</c:when>
						<c:otherwise><input name="status" class="status" type="checkbox" value="1"/></c:otherwise>
					</c:choose>	
				</td>
			</tr>
			<tr>
				<td class="column1"></td>
				<td>
					<input type="submit"  value="Lưu" >
					<input type="submit"  value="Tìm kiếm" class="btn-search">
				</td>
			</tr>
		</table>	
	</form>
</div>
<c:choose>
	<c:when test="${!empty auths}">	
		<c:choose>
			<c:when test="${loginAuth.objectType == 1}"><h3>Danh sách tổ chức, cá nhân</h3></c:when>
			<c:otherwise><h3>Danh sách nhân viên</h3></c:otherwise>
		</c:choose>		
		<table class="tb-content" style="width: 100%">
			<tr>
				<th style="width: 80%">Email </th><th>Trạng thái</th>
			</tr>
			<c:forEach items="${auths}" var="obj">
				<tr>
					<td>
						<a href="javascript:void(0)" onclick="showForm('${obj.id}','${obj.accountName}','${obj.roleId}','${obj.companyId}','${obj.active}')">${obj.accountName}</a>
					</td>
					
					<td style="text-align: center;">
						<c:choose>
							<c:when test="${obj.active == 1}"><input type="checkbox" checked="checked" disabled="disabled"></c:when>
							<c:otherwise>-</c:otherwise>
						</c:choose>				
				</tr>
			</c:forEach>
		</table>
		<div class="employee-ajax"></div>
	</c:when>
	<c:otherwise><p class="tb-empty"><spring:message code="label.tb.empty"/></p></c:otherwise>
</c:choose> 

